package com.aaa.java05;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/6 15:12
 * @description：
 * @modified By：
 * @version:
 */
public class StringTest {
    public static void main(String[] args) {
  /*      String  s1="abc";
        String  s2= new String("abc");
        String  s3= new String("abc");
        System.out.println(s1==s2);
        System.out.println(s1==s3);
        System.out.println(s2==s3);
        System.out.println(s1.equals(s2));*/
        //==是比较内存地址，equals比较内容，内存地址一致，equals必然为true
/*
        String  name="ab,cd,efg";
*/
/*        String  name2= new String("chenjian");*//*
        System.out.println("长度："+name.length());
        //从下标3 开始，包含下标3
        System.out.println("截取字符串"+name.substring(3));
        //从下标3开始，到下标5截止，不包含下标5，包含下标3
        System.out.println("截取字符串"+name.substring(3,5));
        //endsWith,以xxx结尾
        boolean endsWith = name.endsWith("x");
        //startWith,以xxx结尾
        boolean startWith = name.startsWith("ab");
        System.out.println(endsWith);
        System.out.println(startWith);
        int index = name.indexOf('c');
        System.out.println(index);
        System.out.println("===============");
        String replace = name.replace("fg", "xxx");
        System.out.println(name);
        System.out.println(replace);

        String[] strings = name.split(",");
        System.out.println("数组的长度："+strings.length);
        for (String string : strings) {
            System.out.println(string);
        }*/


        System.out.println("=====================================");
        //字符串拼接
      /* long start = System.currentTimeMillis();
         String str="";
        for (int i = 0; i < 100000; i++) {
            str=str+i;
        }
        long end = System.currentTimeMillis();
        System.out.println("拼接字符串花费的时间："+(end-start));
         System.out.println("拼接之后的"+str.toString());*/
        //使用stringbuffer字符串拼接
       /* long start = System.currentTimeMillis();
        StringBuffer str=new StringBuffer("");
        for (int i = 0; i < 1000000; i++) {
            str.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println("stringBuffer拼接字符串花费的时间："+(end-start));*/

     //   System.out.println("拼接之后的"+str.toString());
        //使用stringbuilder字符串拼接
     /*   long start = System.currentTimeMillis();
        StringBuilder str=new StringBuilder("");
        for (int i = 0; i < 1000000; i++) {
            str.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println("StringBuilder拼接字符串花费的时间："+(end-start));*/
    }
}
